using DaprPlus.AspNetCore.Mvc.Filters;
using DaprPlus.Domain;
using Todos.Application.TodoItems.Commands;
using Todos.Application.TodoItems.Queries;

using OSharp.Filter;


namespace Todos.Api.Controllers;

[ApiResultWrapperFilter]
public class TodoListController(IMediator mediator) : ApiControllerBase
{
    [HttpPost("read")]
    [Produces<PageResult<TodoListOutDto>>]
    public async Task<ActionResult> PageAsync([FromBody] GetTodoListPageQuery query)
    {
        var result = await mediator.Send(query);
        return Ok(result);
    }

    [HttpPost]
    [Produces<ApiResult>]
    public async Task<ActionResult> CreateAsync([FromBody] CreateTodoListCommand command)
    {
        var result = await mediator.Send(command);
        return Ok(result);
    }

    [HttpPut]
    [Produces<ApiResult>]
    public async Task<ActionResult> UpdateAsync([FromBody] UpdateTodoListCommand command)
    {
        var result = await mediator.Send(command);
        return Ok(result);
    }

    [HttpDelete]
    [Produces<ApiResult>]
    public async Task<ActionResult> DeleteAsync([FromBody] DeleteTodoListCommand command)
    {
        var result = await mediator.Send(command);
        return Ok(result);
    }

    // TodoItem 相关 API

    [HttpPost("items/{listId}")]
    [Produces<PageResult<TodoItemOutDto>>]
    public async Task<ActionResult> GetItemsAsync(long listId, [FromBody]GetTodoItemPageQuery query)
    {
        query.ListId = listId;
        var result = await mediator.Send(query);
        return Ok(result);
    }

    [HttpPost("items")]
    [Produces<ApiResult>]
    public async Task<ActionResult> AddItemAsync([FromBody] AddTodoItemCommand command)
    {
        var result = await mediator.Send(command);
        return Ok(result);
    }

    [HttpPut("items")]
    [Produces<ApiResult>]
    public async Task<ActionResult> UpdateItemAsync([FromBody] UpdateTodoItemCommand command)
    {
        var result = await mediator.Send(command);
        return Ok(result);
    }

    [HttpDelete("items")]
    [Produces<ApiResult>]
    public async Task<ActionResult> DeleteItemAsync([FromBody]DeleteTodoItemCommand command)
    {
        var result = await mediator.Send(command);
        return Ok(result);
    }

    [HttpPost("items/status")]
    [Produces<ApiResult>]
    public async Task<ActionResult> ChangeItemStatusAsync([FromBody] ChangeTodoItemStatusCommand command)
    {
        var result = await mediator.Send(command);
        return Ok(result);
    }

}